#include <fcntl.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <termios.h>
#include "CRC_Check.h"
#include <linux/serial.h>
#include <memory.h>
#include <opencv2/opencv.hpp>

// subscibtion
struct VisionData
{
    uint8_t header = 0xA5;
    uint8_t mode;
    uint8_t CRC8 = 0;
    float pitch;
    float yaw;
    uint8_t is_find_target;
    uint8_t is_find_dafu;
    // uint8_t anti_top_change_armor;
    uint16_t CRC16 = 0;
}__attribute__((packed));

// publish
struct CarData
{
    uint8_t header = 0xA5;
    uint8_t mode;
    uint8_t CRC8;
    float yaw;
    float pitch;
    float shoot_speed; // uint8_t
    uint8_t my_color;
    uint8_t tmp;       //no
    uint16_t CRC16;
}__attribute__((packed));


class SerialPort
{
public:
    explicit SerialPort();
    ~SerialPort();
    bool init();
    bool recieve(CarData& cardata);
    void send(const VisionData& vd);
    void close_port();
    int result;
    uint8_t mode;

private:
    void set_brate();
    int set_bit();
    int fd;
    int boudrate, databits, stopbits, parity;
    unsigned char rdata[4096];
    unsigned char Tdata[30];
};


